package pl.wroc.uni.ii.evolution.engine.individuals;

import java.util.Arrays;

import pl.wroc.uni.ii.evolution.engine.prototype.EvIndividual;

/**
 * EvPermutationIndividual
 *
 * @author Donata Malecka, Piotr Baraniak
 */
public class EvPermutationIndividual extends EvIndividual {

	/**
   * 
   */
  private static final long serialVersionUID = 6050861148116245519L;
  private int[] chromosome;
  
  
	public EvPermutationIndividual(int d) {
		chromosome = new int[d];
	}
  
  
  public EvPermutationIndividual(int[] chromosome) {
    this.chromosome = chromosome.clone();
  }
  
  
	@Override
	public EvPermutationIndividual clone() {
    EvPermutationIndividual new_individual = new EvPermutationIndividual(chromosome.clone());
    new_individual.setObjectiveFunction(getObjectiveFunction());
		return new_individual;
	}
  
  public int[] getChromosome() {
    return chromosome.clone();
  }
  
  public void setChromosome(int[] chromosome) {
    this.chromosome = chromosome.clone();
    invalidate();
  }
  
  public String toString() {
    String str = "";
    for (int i = 0; i < chromosome.length; i++) {
      str +=  i + "->" + chromosome[i] + ", ";
    }
    str = str.substring(0,str.length()-2);
    return str;
  }
  
  public int getGeneValue(int i) {
    return chromosome[i];
  }
  
  public void setGeneValue(int i, int value) {
    chromosome[i] = value;
    this.invalidate();
  }
  
  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    final EvPermutationIndividual other = (EvPermutationIndividual) obj;
    if (!Arrays.equals(chromosome, other.chromosome))
      return false;
    return true;
  }
}
